//
//  UILabel+dynamicSize.m
//  TXYUploadSDK
//
//  Created by kodywu on 9/4/15.
//  Copyright (c) 2015 Qzone. All rights reserved.
//

#import "UILabel+dynamicSize.h"

@implementation UILabel (dynamicSize)

-(void)resizeToFit
{
    [self setNumberOfLines:0];
    [self setLineBreakMode:NSLineBreakByCharWrapping];
    if (self.text == nil) {
        self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, self.bounds.size.width, 0);
        return;
    }
    //调整原始窗口大小以适应文字的长短
    CGSize  dstSize = CGRectInfinite.size;
    dstSize.width = self.bounds.size.width;
    dstSize = [self.text sizeWithFont:self.font constrainedToSize:dstSize];
    self.frame = CGRectMake(self.frame.origin.x, self.frame.origin.y, dstSize.width, dstSize.height);
}

@end
